<template>
<div>
    <nav-bar class="detail-nav">
        <img slot="left" class="back" @click="backClick" src="~assets/img/common/back.svg">
        <div slot="center" class="title">
            <span v-for="(item, index) in titleInfos" :key="index" class="title-item" :class="{'active': index===currentIndex}" @click="titleClick(index)">
                {{item}}
            </span>
        </div>

    </nav-bar>
</div>
</template>

<script>
import NavBar from 'common/navbar/NavBar'
export default {
    name: 'DetailNavBar',
    components: {
        NavBar
    },
    data() {
        return {
            currentIndex: 0
        }
    },
    props: {
        titleInfos: {
            type: Array,
            default: () => {
                return ['商品', '参数', '评论', '推荐']
            }
        }
    },
    methods: {
        backClick() {
            this.$router.back()
        },
        titleClick(index) {
            this.currentIndex = index;
            this.$emit('titleClick',index);
        }
    }
}
</script>

<style scoped>
.detail-nav {
    background-color: #fff;
    font-weight: normal;
}

.back {
    margin-top: 10px;
}

.title {
    display: flex;
    font-size: 13px;
}

.title-item.active {
    color: var(--color-high-text);
}

.title-item {
    flex: 1;
}
</style>
